import Vue from 'vue'
import Vuex from 'vuex'
import cookie from '@/assets/util/cookie'

Vue.use(Vuex)

const userInfo = {
  id: 0,
  name: cookie.getCookie('name') || '',
  token: cookie.getCookie('token') || '',
  storeName: cookie.getCookie('storeName') || ''
}

const store = new Vuex.Store({
  state: {
    isLogin: false,
    isLoading: false,
    userInfo: userInfo
  },
  mutations: {
    setUserInfo (state) {
      state.userInfo = {
        id: cookie.getCookie('id'),
        name: cookie.getCookie('name'),
        storeName: cookie.getCookie('storeName'),
        token: cookie.getCookie('token')
      }
    },
    logout (state) {
      cookie.delCookie('id')
      cookie.delCookie('name')
      cookie.delCookie('storeName')
      cookie.delCookie('token')
    }
  }
})

export default store
